//============================================================================
// Name        : slicer.h
// Author      : Yugi
// Version     : 1.0
// Description : 
//============================================================================

#ifndef _SLICER_H
#define _SLICER_H

#include <stdlib.h>
#include <dr_api.h>

#include "bitmap.h"
#include "worklist.h"
#include "cfg.h"

/*
* Generate an initial slice that contains only the target function instructions.
*
* RETURN:	true if initial slice is complete, false otherwise.
* MODIFY:	iList
*			pcfg
*			target
*/
bool init_slice(void *drcontext, instrlist_t *bb, app_pc *target, PCFG pcfg, 
				instrlist_t *iList);

/*
* RETURN:	instructions count of iList
*/
unsigned int count(instrlist_t *iList);

/*
* Dynamic backward slicing
*
* REQUIRE:	iList not NULL
*			worklist not NULL
* RETURN:	bitmap that marks instruction
* MODIFY:	worklist
*/
PSBITMAP dynamic_backward_slice(instrlist_t *iList, PWORKLIST worklist);

/*
* Dynamic forward slicing
*
* REQUIRE:	worklist not NULL
*			iList not NULL
*			iCount is greater than 0
* RETURN:	bitmap that marks instruction
* MODIFY:	worklist
*/
PSBITMAP dynamic_forward_slice(instrlist_t *iList, PWORKLIST worklist);

/*
* Static backward slicing
*
* REQUIRE:	worklist not NULL
*			pcfg not NULL
* MODIFY:	pcfg
*/
void static_backward_slice(void *drcontext, PCFG pcfg, PWORKLIST worklist);

/*
* Static forward slicing
*
* REQUIRE:	worklist not NULL
*			pcfg not NULL
* MODIFY:	pcfg
*/
void static_forward_slice(void *drcontext, PCFG pcfg, PWORKLIST worklist);

/* 
* Print initial slice
*
* REQUIRE:	iList not NULL
*			outfile not NULL
*/
void print_initial_slice(void *drcontext, file_t outfile, instrlist_t *iList);

/*
* Print a slice according to bitmap
*
* REQUIRE:	bitmap not NULL
*			iList not NULL
*			outfile not NULL
*/
void print_dynamic_slice(void *drcontext, file_t outfile, instrlist_t *iList, PSBITMAP bitmap);

#endif /* End of _SLICER_H */
